package ide.modelo;

import java.util.ArrayList;
import java.util.Arrays;
import java.lang.String;

public class Editor {
	private ArrayList<String> lineas;
	private final String FINDELINEA = "\\n";
	
	public void setContenido(String cadena){
		lineas = stringAArrayList(cadena);
	}
	
	public void setCotenido(ArrayList<String> lineas){
		this.lineas = new ArrayList<String>( lineas );
	}
	
	public String getLinea(int numLinea){
		return lineas.get(numLinea);
	}
	
	public String getContenidoComoString(){
		return arrayListAString(lineas);
	}
	
	public ArrayList<String> getContenidoComoLineas(){
		return lineas;
	}
	
	private ArrayList<String> stringAArrayList(String cadena){
		return new ArrayList<String>( Arrays.asList( cadena.split(FINDELINEA) ) );
	}
	
	private String arrayListAString(ArrayList<String> lineas){
		String cadena = new String();
		for(int i = 0; i < lineas.size(); i++){
			if(i != lineas.size() - 1){
				cadena = cadena.concat( lineas.get(i).concat("\n") );
			}else{
				cadena = cadena.concat( lineas.get(i) );
			}
		}
		return cadena;
	}
}
